import pygame
from pygame.sprite import Sprite
from .utils import get_direction

class Bullet(Sprite):
    SPEED = 10

    def __init__(self, start_pos):
        super().__init__()
        self.start_pos = start_pos
        self.image = pygame.Surface((10, 10))
        self.image.fill("red")
        self.rect = self.image.get_rect(center=self.start_pos)
        self.direction = get_direction(pygame.mouse.get_pos(), self.rect.center)
        self.cooldown_timer = 1

    def update(self):
        self.rect.center += self.direction * self.SPEED
        self.destroy()
    
    def destroy(self):
        if self.rect.y < 0 or self.rect.y > 800 or self.rect.x < 0 or self.rect.x > 1000:
            self.kill()
